package com.gzy.rpsm_property.service.serviceIpml;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gzy.rpsm_property.mapper.UserMapper;
import com.gzy.rpsm_property.pojo.PageResult;
import com.gzy.rpsm_property.pojo.user.User;
import com.gzy.rpsm_property.pojo.vo.UnpaidOwner;
import com.gzy.rpsm_property.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
//7.完成UserServiceImpl 实现类
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    //新增account可能触发唯一索引的异常
    public int insertUser(User user) throws DuplicateKeyException, Exception {
        int result = -1;
        result = userMapper.insertUser(user);
        return result;
    }

    @Override
    public int changeUserStatus(User user) {
        return userMapper.changeUserStatus(user);
    }

    @Override
    public User queryById(int id) {
        return userMapper.queryById(id);
    }

    @Override
    public PageResult<User> pageOfOwner(int current, int size) {
        PageHelper.startPage(current,size);
        Page<User> page = userMapper.owners();
        return PageResult.restPage(page);
    }

    @Override
    public PageResult<UnpaidOwner> pageOfUnpaidOwnerList(Integer current, Integer size, Integer typeId) {
        PageHelper.startPage(current,size);
        Page<UnpaidOwner> page = userMapper.unpaidOwnerList(typeId);
        return PageResult.restPage(page);
    }


}
